///*
// * To change this license header, choose License Headers in Project Properties.
// * To change this template file, choose Tools | Templates
// * and open the template in the editor.
// */
//package crawler.parser;
//
//import crawler.common.HTMLUtil;
//import crawler.common.LinkData;
//import crawler.common.PatternData;
//import crawler.common.PostData;
//import crawler.model.PatternModel;
//import crawler.post.StaticCrawler;
//import java.io.IOException;
//import java.util.LinkedList;
//import java.util.List;
//import java.util.concurrent.locks.Lock;
//import java.util.concurrent.locks.ReentrantLock;
//import org.apache.log4j.Logger;
//import org.jsoup.Connection;
//import org.jsoup.Jsoup;
//import org.jsoup.nodes.Document;
//import org.jsoup.nodes.Element;
//import org.jsoup.select.Elements;
//
///**
// *
// * @author LT
// */
//public class ListPostParser {
//    private static final Logger logger = Logger.getLogger(ListPostParser.class);
//    private static final Lock createLock_ = new ReentrantLock();
//    private static ListPostParser _instance = null;
//
//    public static ListPostParser getInstance() {
//        if (_instance == null) {
//            createLock_.lock();
//            try {
//                if (_instance == null) {
//                    _instance = new ListPostParser();
//
//                }
//            } finally {
//                createLock_.unlock();
//            }
//        }
//        return _instance;
//    }
//    
//    public List<PostData> getListPost(LinkData linkData){
//        StaticCrawler staticCrawler = StaticCrawler.getInstance();
//        List<PostData> links = new LinkedList<>();
//        try {
//            PatternModel patternModel = PatternModel.getInstance();
//
//            PatternData patternData = patternModel.getById(linkData.getPatternId());
//            Connection cnn = Jsoup.connect(linkData.getUrl());
//            cnn.header("User-agent", "	Mozilla/5.0 (Windows NT 6.1; WOW64; rv:33.0) Gecko/20100101 Firefox/33.0");
//            Document doc = cnn.get();
//            Elements eLinks = doc.select(patternData.getLink());
//            Elements eThumb = doc.select(patternData.getThumb());
//            int index = 0;
//            for(Element e : eLinks){
//                PostData postData = new PostData();
//                postData.setUrl(HTMLUtil.toAbsoluteURL(e.attr("href"), linkData.getUrl()));
//                String thumb = eThumb.get(index++).attr("src");
//                thumb = staticCrawler.crawImage(thumb, "timsao", patternData.getName());
//                postData.setThumb(thumb);
//                links.add(postData);
//            }
//            
//        } catch (IOException ex) {
//            logger.error(ex.getMessage(), ex);
//        }    
//       return links;    }
//    
//}
